<?php

namespace App\Service\UserService;

use App\Service\BaseService;
use App\Service\Code\Normal;
use App\Service\VendorClient\Shopgdf\ShopgdfApiClient;
use App\Model\CommodityModel\SupplierCompany;
/**
 * 艾禧汇-gdf服务中心
 * @author chenyun
 */
class GdfService extends BaseService
{
    protected $GdfApiClient;
    protected $config;
    protected $extends;
    /**
     * 接收消息数据
     * @param string $messageType
     * @param array $data
     */
    public function MessageRev(string $messageType,string $supplierId,array $data)
    {
        $config = $this->getConfig($supplierId);
        //如果没有配置就暂停查询
        if ($config['code'] != Normal::SUC)
        {
            return $config;
        }
        $this->gdfApiClient = new ShopgdfApiClient($config["data"]["JsonBody"]);
        $res = $this->gdfApiClient->queryGoodsDetails($data);
        return Normal::returnCode(Normal::SUC,"请求成功",$res);
    }
    private function getConfig($supplierId)
    { 
        //查询菜鸟配置
        $supplierInfo = SupplierCompany::instance()->getSupplierListById($supplierId);
        if(empty($supplierInfo) or empty($supplierInfo["JsonBody"])){
            return Normal::returnCode(Normal::FAIL,"没有查询到对应的配置，请核实！");
        }
        return Normal::returnCode(Normal::SUC,"处理完成",$supplierInfo);
    }
}